package com.luber.backstage.service.impl;

import java.util.List;

import com.luber.backstage.domain.EticketVehicleModel;
import com.luber.backstage.domain.vo.EticketVehicleModelVO;
import com.luber.backstage.mapper.EticketInvalidSeatMapper;
import com.luber.backstage.mapper.EticketVehicleModelMapper;
import com.luber.backstage.service.IEticketVehicleModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 【车辆型号】Service业务层处理
 *
 * @author luber
 * @date 2021-01-19
 */
@Service
public class EticketVehicleModelServiceImpl implements IEticketVehicleModelService
{
    @Autowired
    private EticketVehicleModelMapper eticketVehicleModelMapper;
    @Autowired
    private EticketInvalidSeatMapper eticketInvalidSeatMapper;


    /**
     * 查询【车辆型号】
     *
     * @param id 【车辆型号】ID
     * @return 【车辆型号】
     */
    @Override
    public EticketVehicleModelVO selectEticketVehicleModelById(Long id)
    {
        return eticketVehicleModelMapper.selectEticketVehicleModelById(id);
    }

    /**
     * 查询【车辆型号】列表
     *
     * @param eticketVehicleModel 【车辆型号】
     * @return 【车辆型号】
     */
    @Override
    public List<EticketVehicleModelVO> selectEticketVehicleModelList(EticketVehicleModel eticketVehicleModel)
    {
        return eticketVehicleModelMapper.selectEticketVehicleModelList(eticketVehicleModel);
    }

    /**
     * 新增【车辆型号】
     *
     * @param eticketVehicleModel 【车辆型号】
     * @return 结果
     */
    @Override
    public int insertEticketVehicleModel(EticketVehicleModel eticketVehicleModel)
    {
        try {
            return eticketVehicleModelMapper.insertEticketVehicleModel(eticketVehicleModel);
        }catch (Exception e){
            return 0;
        }

    }

    /**
     * 修改【车辆型号】
     *
     * @param eticketVehicleModel 【车辆型号】
     * @return 结果
     */
    @Override
    public int updateEticketVehicleModel(EticketVehicleModel eticketVehicleModel)
    {
        eticketInvalidSeatMapper.deleteEticketInvalidSeatByModelId(eticketVehicleModel.getId());
        return eticketVehicleModelMapper.updateEticketVehicleModel(eticketVehicleModel);
    }

    /**
     * 批量删除【车辆型号】
     *
     * @param ids 需要删除的【车辆型号】ID
     * @return 结果
     */
    @Override
    public int deleteEticketVehicleModelByIds(Long[] ids)
    {
        //级联删除车辆座次和车辆座次无效表
        eticketInvalidSeatMapper.deleteEticketInvalidSeatByModelIds(ids);
        return eticketVehicleModelMapper.deleteEticketVehicleModelByIds(ids);
    }

    /**
     * 删除【车辆型号】信息
     *
     * @param id 【车辆型号】ID
     * @return 结果
     */
    @Override
    public int deleteEticketVehicleModelById(Long id)
    {
        //级联删除车辆座次和车辆座次无效表
        eticketInvalidSeatMapper.deleteEticketInvalidSeatByModelId(id);
        return eticketVehicleModelMapper.deleteEticketVehicleModelById(id);
    }
}
